//
//  SHCollectionHead.m
//  SimpleHappy
//
//  Created by 张超 on 15/11/24.
//  Copyright © 2015年 RockyFung. All rights reserved.
//

#import "SHCollectionHead.h"
#import "Define.h"
#import "SHLoginView.h"
#import "MyController.h"
#import <BmobSDK/Bmob.h>


@interface SHCollectionHead ()<UIActionSheetDelegate,UINavigationControllerDelegate, UIImagePickerControllerDelegate>


@end

@implementation SHCollectionHead

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

        self.backgroundColor = [UIColor blackColor];
        
        // 黑色视图上的头像
        self.headImage = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KScreenWidth / 6, KScreenWidth / 6)];
        self.headImage.center = CGPointMake(KScreenWidth / 2, KScreenHeight / 7);
//        headImage.backgroundColor = [UIColor whiteColor];
        self.headImage.image = [UIImage imageNamed:@"long.png"];
        self.headImage.layer.cornerRadius = _headImage.bounds.size.height / 2;
        self.headImage.layer.masksToBounds = YES; // 图片变圆后去掉多余边框
        self.headImage.userInteractionEnabled = YES;
                [self addSubview:_headImage];
        
        
        // 黑色视图上的用户名标题
        self.userLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, frame.size.height - KScreenWidth / 7.5, KScreenWidth, KScreenWidth / 18)];
        self.userLabel.textAlignment = NSTextAlignmentCenter;
        self.userLabel.textColor = [UIColor whiteColor];
       [self addSubview:_userLabel];
      
    }
    return self;
}

/*
#pragma mark - actionSheet代理方法 -
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
   
    // 调用相机
    if (buttonIndex == 0)
    {
        NSLog(@"调用相机");
        // 判断打开系统的相机或者相册有没有成功
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
        {
            NSLog(@"打开相机成功");
            UIImagePickerController *picker = [[UIImagePickerController alloc]init];
            // imagePickerController的类型，决定显示出来的效果
            picker.sourceType = UIImagePickerControllerSourceTypeCamera;// 打开相机
            // 是否有编辑状态
            picker.allowsEditing = YES;
            // 设置代理 点击选择的时候自动去调用代理方法
            // 需要遵守 UINavigationControllerDelegate, UIImagePickerControllerDelegate
            picker.delegate = self;
            [[self callVC] presentViewController:picker animated:YES completion:nil];
        }
        else
        {
            UIAlertView *alerView = [[UIAlertView alloc]initWithTitle:@"提示" message:@"没有摄像头" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
            [alerView show];
        }
        
    }
    // 调用相册
    else if (buttonIndex == 1)
    {
        NSLog(@"调用相册");
        // 判断打开系统的相机或者相册有没有成功
        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
        {
            NSLog(@"打开相册成功");
            UIImagePickerController *picker = [[UIImagePickerController alloc]init];
            // imagePickerController的类型，决定显示出来的效果
            //        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;// 打开相册
            // 是否有编辑状态
            picker.allowsEditing = YES;
            // 设置代理 点击选择的时候自动去调用代理方法
            // 需要遵守 UINavigationControllerDelegate, UIImagePickerControllerDelegate
            picker.delegate = self;
            [[self callVC] presentViewController:picker animated:YES completion:nil];
        }
        else
        {
            NSLog(@"打开相册失败");
        }
    }
}

#pragma mark - imagePicker代理方法 -
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    NSLog(@"ok");
    // 将选中的图片赋值给UIImageView
    // 通过字典的key值，取出对应的value值，value是我们从相册选取的图片
    self.headImage.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    // 将图片存入到系统相册
    //    UIImageWriteToSavedPhotosAlbum(self.imageView.image, nil, nil, nil);
    // 将这个界面模态回去dismiss
    [[self callVC] dismissViewControllerAnimated:YES completion:nil];
}

- (UIViewController *)callVC
{
    // 获取控制器
    id object = [self nextResponder];
    while (![object isKindOfClass:[UIViewController class]] &&
           object != nil) {
        object = [object nextResponder];
    }
    UIViewController *uc=(UIViewController*)object;
    return uc;
}
*/
 
@end
